/**
 * Copyright (c) 2002-2012 旭鸣信息
 * All rights reserved. 
 * File：CountryListDirective.java
 * History: Dec 27, 2012: Initially created, liuzhi.
 */
package com.xteam.ecsystem.directive;

import static freemarker.template.ObjectWrapper.DEFAULT_WRAPPER;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xteam.ecsystem.base.Constant;
import com.xteam.ecsystem.entities.BaseDistributeRegion;
import com.xteam.ecsystem.service.front.FrontUserAddrService;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

/**
 * 一级区域(国家列表) 标签。
 * @author liuzhi
 */
@Service
public class CountryListDirective implements TemplateDirectiveModel {
	
	@Autowired
	private FrontUserAddrService userAddrService;

	@SuppressWarnings("unchecked")
	public void execute(Environment env, Map params, TemplateModel[] loopVars,
			TemplateDirectiveBody body) throws TemplateException, IOException {
		List<BaseDistributeRegion> listObj = this.userAddrService.getRegionList("", "0");
		
		env.setVariable(Constant.VAR_BDRLIST_COUNTRY.value(),DEFAULT_WRAPPER.wrap(listObj));
		body.render(env.getOut());
	}
}
